package com.cdks.wuxiu.api.service.mysql;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cdks.wuxiu.api.component.constant.Constant;
import com.cdks.wuxiu.api.mapper.WithdrawOrderInfoMapper;
import com.cdks.wuxiu.entity.mysql.WithdrawOrderInfo;

import java.util.List;

import org.springframework.stereotype.Service;


/**
 * 提现订单表 服务实现类
 */
@Service
public class WithdrawOrderInfoServiceImpl extends ServiceImpl<WithdrawOrderInfoMapper, WithdrawOrderInfo> implements WithdrawOrderInfoService {
    @Override
    public List<WithdrawOrderInfo> getRecord(long userId, int page, long start, long stop) {
        QueryWrapper<WithdrawOrderInfo> wrapper  = new QueryWrapper<>();
        wrapper.lambda().between(WithdrawOrderInfo::getCreateTime, start, stop)
                        .eq(WithdrawOrderInfo::getUserId, userId)
                        .select(WithdrawOrderInfo::getCreateTime,
                                WithdrawOrderInfo::getMoney,
                                WithdrawOrderInfo::getCoin,
                                WithdrawOrderInfo::getType,
                                WithdrawOrderInfo::getStatus,
                                WithdrawOrderInfo::getRemark);
        wrapper.last("LIMIT " + page * Constant.LIST_PAGE_SIZE + "," + Constant.LIST_PAGE_SIZE);

        return baseMapper.selectList(wrapper);
    }

    @Override
    public WithdrawOrderInfo getLastValid(long userId) {
        QueryWrapper<WithdrawOrderInfo> wrapper  = new QueryWrapper<>();
        wrapper.lambda().ne(WithdrawOrderInfo::getStatus, Constant.AUDIT_STATUS_REFUSE)
                        .eq(WithdrawOrderInfo::getUserId, userId)
                        .orderByDesc(WithdrawOrderInfo::getId);
        wrapper.last(" LIMIT 1");

        return baseMapper.selectOne(wrapper);
    }
}
